﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dhsystem.Main;
using dhSystemBLL.produceBLL ;
using baseSet.importExport;
using FastReport;
using dhDataAcess.baseBLL;
using dhSystemBLL.orderData;
using baseSet.power;
using dhDataAcess.dataAcess;

namespace dhsystem.produceForm.pdrk
{
    public partial class Frmpdfpjlb : Form
    {
        pdfpjlbBLL pdfpjib= new pdfpjlbBLL();
        pdpqbBLL pdpqb = new pdpqbBLL();
        custListBLL custList = new custListBLL();
        string state;
        public Frmpdfpjlb()
        {
            InitializeComponent();
        }
        //打开窗口时显示列表数据
        private void Frmpdfpjlb_Load(object sender, EventArgs e)
        {
            bindingSourcecustList.DataSource = custList.getcustListAll();
            comboBoxcustNum.DataSource = bindingSourcecustList;
            comboBoxcustNum.DisplayMember = "custName";
            comboBoxcustNum.ValueMember = "custNum";
            bgSourcecustlist2.DataSource = custList.getcustListAll();
            comboBox3.DataSource = bgSourcecustlist2;
            comboBox3.DisplayMember = "custName";
            comboBox3.ValueMember = "custNum";
            bgSourcecustlist3.DataSource = custList.getcustListAll();
            comboBox4.DataSource = bgSourcecustlist3;
            comboBox4.DisplayMember = "custName";
            comboBox4.ValueMember = "custNum";
            bindingSourcepdfpjlb.DataSource = pdpqb.getV_piaoranpaiqiAllBybillStatus("开始染色");
            dGridpdfpjlb.DataSource = bindingSourcepdfpjlb;
            DcolumnSet.colSet(moduleInfo.V_piaoranpaiqi, dGridpdfpjlb);
            toolStripStatusLabel1.Text = "数据总条数:" + dGridpdfpjlb.RowCount.ToString() + "条";


            sysDataSet.modulAaccessDataTable modulAaccess = powerSet.modulPower(moduleInfo.pdfpjlb );
            foreach (sysDataSet.modulAaccessRow modulAaccessRow in modulAaccess)
            {
                buttonQuery.Enabled = modulAaccessRow.showAc;
                toolAdd.Enabled = modulAaccessRow.addAc;
                toolStripMenuItem2.Enabled = modulAaccessRow.addAc;
                胚带发胚ToolStripMenuItem.Enabled = modulAaccessRow.addAc;
                toolEdit.Enabled = modulAaccessRow.editAc;
                取消发胚ToolStripMenuItem.Enabled = modulAaccessRow.editAc;
                取消欠数发胚ToolStripMenuItem.Enabled = modulAaccessRow.editAc;
                toolDel.Enabled = modulAaccessRow.delAc;
                toolStripMenuItem1.Enabled = modulAaccessRow.printAc;
                toolExport.Enabled = modulAaccessRow.exportAc;
                //buttImport.Enabled = modulAaccessRow.importAc;

            }
        }
        //新增按钮，显示新增窗口
        private void toolAdd_Click(object sender, EventArgs e)
        {
            state = "新增";
            FrmpdfpjlbAdd pdfpjlbAdd = new FrmpdfpjlbAdd(bindingSourcepdfpjlb, state,"","");
            pdfpjlbAdd.ShowDialog();
        }
        //工具栏查询按钮，查询所有列表数据
        private void toolQuery_Click(object sender, EventArgs e)
        {
            FrmDataQuery query = new FrmDataQuery(moduleInfo.pdfpjlb);
            DialogResult result = query.ShowDialog();
            if (result == DialogResult.Yes)
            {
                dGridpdfpjlb.DataSource = query.rTable;
            }
        }
        //工具栏的编辑按钮,修改数据
        private void toolEdit_Click(object sender, EventArgs e)
        {
            state = "编辑";
            FrmpdfpjlbAdd pdfpjlbAdd = new FrmpdfpjlbAdd(bindingSourcepdfpjlb, state,"","");
            pdfpjlbAdd.ShowDialog();
        }
        //删除按钮，删除选中行数据
        private void toolDel_Click(object sender, EventArgs e)
        {
            string recordid = dGridpdfpjlb.Rows[dGridpdfpjlb.CurrentRow.Index].Cells[0].Value.ToString();
            string billStatus = dGridpdfpjlb.CurrentRow.Cells["billStatus"].Value.ToString();
            if (billStatus == "结算")
            {
                MessageBox.Show("此订单已经结算，不能删除。如需删除请反结算");
                return;
            }
            try
            {
                DialogResult result = MessageBox.Show("是否删除记录：" + recordid + "！", "提示信息", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {

                    bindingSourcepdfpjlb.DataSource = pdfpjib.pdfpjlbDel(recordid);
                    dGridpdfpjlb.DataSource = bindingSourcepdfpjlb;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            bindingSourcepdfpjlb.DataSource = pdfpjib.getpdfpjlbAll();
        }
        //查询按钮，按条件查询数据
        private void buttonQuery_Click(object sender, EventArgs e)
        {

        }
        //刷新按钮
        private void buttupdate_Click(object sender, EventArgs e)
        {
            bindingSourcepdfpjlb.DataSource = pdfpjib.getpdfpjlbAll();
            dGridpdfpjlb.DataSource = bindingSourcepdfpjlb;
            DcolumnSet.colSet(moduleInfo.pdfpjlb , dGridpdfpjlb);
            toolStripStatusLabel1.Text = "数据总条数:" + dGridpdfpjlb.RowCount.ToString() + "条";
        }
        //工具栏退出按钮，退出窗口
        private void toolExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //datagridview第一列显示行号
        private void dGridpdfpjlb_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
        {
            e.Row.HeaderCell.Value = string.Format("{0}", e.Row.Index + 1);
        }

        private void toolStripranse_Click(object sender, EventArgs e)
        {
            Frmcoloration coloration = new Frmcoloration();
            coloration.ShowDialog();
        }

        private void toolExport_Click(object sender, EventArgs e)
        {
            FrmExcelExport frm = new FrmExcelExport(moduleInfo.pdfpjlb , dGridpdfpjlb , "胚带发胚信息");
            frm.ShowDialog();
        }
        //漂染单打印
        private void toolPrint_Click(object sender, EventArgs e)
        {
            string billoNo = dGridyifp.CurrentRow.Cells["billoNo"].Value.ToString();
            Report r = new Report();
            DataSet ds = new DataSet();
            ds.Tables.Add(pdfpjib.getV_piaoranorderAllBybilloNo(billoNo));
            r.Load(@"E:\东华软件项目\报表\piaoranorder.frx");
             //r.Load(@"\\192.168.0.27\东华软件\报表\piaoranorder.frx");
            r.RegisterData(ds);
            r.Design();
        }

        private void 胚带发胚ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            string billoNo = dGridpdfpjlb.CurrentRow.Cells["billoNo"].Value.ToString();
  
            bindingSourcepdpqb.DataSource = pdpqb.getV_piaoranpaiqiAllBybilloNo(billoNo);
            FrmpdfpjlbAdd pdpqbAdd = new FrmpdfpjlbAdd(bindingSourcepdpqb, "新增",billoNo,"" );
            DialogResult result = pdpqbAdd.ShowDialog();
            if (result == DialogResult.Yes)
            {
                bindingSourcepdfpjlb.DataSource = pdpqb.getV_piaoranpaiqiAllBybillStatus("开始染色");
                dGridpdfpjlb.DataSource = bindingSourcepdfpjlb;
                DcolumnSet.colSet(moduleInfo.V_piaoranpaiqi, dGridpdfpjlb);
                toolStripStatusLabel1.Text = "数据总条数:" + dGridpdfpjlb.RowCount.ToString() + "条";
            }
        }

        private void tabControl1_Selected(object sender, TabControlEventArgs e)
        {
            //未发胚
            if (e.TabPage == tabPage1)
            {
                bindingSourcepdfpjlb.DataSource = pdpqb .getV_piaoranpaiqiAllBybillStatus ("开始染色");
                dGridpdfpjlb.DataSource = bindingSourcepdfpjlb;
                DcolumnSet.colSet(moduleInfo.V_piaoranpaiqi, dGridpdfpjlb);
                toolStripStatusLabel1.Text = "数据总条数:" + dGridpdfpjlb.RowCount.ToString() + "条";
            }
            //已发胚
            if (e.TabPage == tabPage2)
            {
                bindingSourceyifap.DataSource = pdfpjib.getV_piaoranorderAllBybillStatus("已发胚");
                dGridyifp.DataSource = bindingSourceyifap;
                DcolumnSet.colSet(moduleInfo.V_piaoranorder , dGridyifp);
            }
            //欠数
            if (e.TabPage == tabPage3)
            {
                bgSourceqianshu.DataSource = pdpqb.getV_piaoranpaiqiAllBybillStatus("欠数");
                dGridViewqianshu.DataSource = bgSourceqianshu;
                DcolumnSet.colSet(moduleInfo.V_piaoranpaiqi, dGridViewqianshu);
            }
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            string billoNo = dGridyifp.CurrentRow.Cells["billoNo"].Value.ToString();
            Report r = new Report();
            DataSet ds = new DataSet();
            ds.Tables.Add(pdfpjib.getV_piaoranorderAllBybilloNo (billoNo));
           // r.Load(@"E:\东华软件项目\报表\piaoranorder.frx");
            r.Load(@"\\192.168.0.27\东华软件\报表\piaoranorder.frx");
            r.RegisterData(ds);
          //r.Design();
           r.Show();

        }

        private void 取消发胚ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult result = MessageBox.Show("是否取消发胚", "提示信息", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    //string recordid = dGridpdfpjlb.Rows[dGridpdfpjlb.CurrentRow.Index].Cells[0].Value.ToString();
                    string billoNo = dGridyifp.CurrentRow.Cells["billoNo"].Value.ToString();
                    basicSql.getpdpqbbillStatusUpdate(billoNo, "开始染色");

                   // string billNo = dGridyifp.Rows[dGridyifp.CurrentRow.Index].Cells[1].Value.ToString();


                    bindingSourceyifap.DataSource = pdfpjib.pdfpjlbDel(billoNo);

         
                    //bindingSourceyifap.DataSource = pdfpjib.getV_piaoranorderAllBybillStatus("已发胚");
                    //dGridyifp.DataSource = bindingSourceyifap;
                    //DcolumnSet.colSet(moduleInfo.V_piaoranorder, dGridyifp);
                    //MessageBox.Show("取消发胚成功");
                    tab1.SelectedIndex=0;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        private void comboBoxcustNum_SelectedIndexChanged(object sender, EventArgs e)
        {
            bindingSourcepdfpjlb.DataSource = basicSql.getV_piaoranpaiqi("%" + comboBoxcustNum.Text + "%");
            dGridpdfpjlb.DataSource = bindingSourcepdfpjlb;
            DcolumnSet.colSet(moduleInfo.V_piaoranpaiqi, dGridpdfpjlb);
        }

        private void toolSave_Click(object sender, EventArgs e)
        {

        }

        private void buttonQuery_Click_1(object sender, EventArgs e)
        {
            try
            {
                bindingSourcepdfpjlb.DataSource = basicSql.getV_piaoranpaiqiByorderDetailNo("%" + textorderDetailNoQuery.Text + "%");
                dGridpdfpjlb.DataSource = bindingSourcepdfpjlb;
                DcolumnSet.colSet(moduleInfo.V_piaoranpaiqi, dGridpdfpjlb);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            try
            {
                bindingSourceyifap.DataSource = basicSql.getV_piaoranorderByorderDetailNoyifp("%" + textMatNameQuery.Text + "%");
                dGridyifp.DataSource = bindingSourceyifap;
                DcolumnSet.colSet(moduleInfo.V_piaoranorder, dGridyifp);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        private void comboBoxyifp_SelectedIndexChanged(object sender, EventArgs e)
        {
            //bindingSourceyifap.DataSource = basicSql.getV_piaoranorder("%" + comboBoxcustNum.Text + "%");
            //dGridyifp.DataSource = bindingSourceyifap;
            //DcolumnSet.colSet(moduleInfo.V_piaoranorder, dGridyifp);
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {

            string billoNo = dGridViewqianshu.CurrentRow.Cells["billoNo"].Value.ToString();
            string yujiqty = dGridViewqianshu.CurrentRow.Cells["yuqty"].Value.ToString();
            bindingSourcepdpqb.DataSource = pdpqb.getV_piaoranpaiqiAllBybilloNo(billoNo);
            FrmpdfpjlbAdd pdpqbAdd = new FrmpdfpjlbAdd(bindingSourcepdpqb, "欠数", billoNo, yujiqty);
            DialogResult result = pdpqbAdd.ShowDialog();
            if (result == DialogResult.Yes)
            {
                bgSourceqianshu.DataSource = pdpqb.getV_piaoranpaiqiAllBybillStatus("欠数");
                dGridViewqianshu.DataSource = bgSourceqianshu;
                DcolumnSet.colSet(moduleInfo.V_piaoranpaiqi, dGridViewqianshu);
            }
        }

        private void 取消欠数发胚ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult result = MessageBox.Show("是否取消发胚", "提示信息", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    //string recordid = dGridpdfpjlb.Rows[dGridpdfpjlb.CurrentRow.Index].Cells[0].Value.ToString();
                    string billoNo = dGridyifp.CurrentRow.Cells["billoNo"].Value.ToString();
                    basicSql.getpdpqbbillStatusUpdate(billoNo, "欠数");

                    // string billNo = dGridyifp.Rows[dGridyifp.CurrentRow.Index].Cells[1].Value.ToString();


                    bindingSourceyifap.DataSource = pdfpjib.pdfpjlbDel(billoNo);
                    tab1.SelectedIndex = 0;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        private void buttselectcustNum_Click(object sender, EventArgs e)
        {
            string field;
            field = "custNum";
            Frmprodutselect productselect = new Frmprodutselect(moduleInfo.custList, field);
            DialogResult result = productselect.ShowDialog();
            if (result == DialogResult.Yes)
            {
                comboBoxcustNum.SelectedValue = productselect.pname;
            }
        }

        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            bindingSourceyifap.DataSource = basicSql.getV_piaoranorderbycustlist("%" + comboBox3.Text + "%");
            dGridyifp.DataSource = bindingSourceyifap;
            DcolumnSet.colSet(moduleInfo.V_piaoranorder, dGridyifp);
        }

        private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
        {
            bgSourceqianshu.DataSource = basicSql.getV_piaoranpaiqibycustlist("%" + comboBox4.Text + "%");
            dGridyifp.DataSource = bgSourceqianshu;
            DcolumnSet.colSet(moduleInfo.V_piaoranpaiqi, dGridViewqianshu);
        }

        private void button9_Click(object sender, EventArgs e)
        {
            string field;
            field = "custNum";
            Frmprodutselect productselect = new Frmprodutselect(moduleInfo.custList, field);
            DialogResult result = productselect.ShowDialog();
            if (result == DialogResult.Yes)
            {
                comboBox3.SelectedValue = productselect.pname;
            }
        }

        private void button10_Click(object sender, EventArgs e)
        {
            string field;
            field = "custNum";
            Frmprodutselect productselect = new Frmprodutselect(moduleInfo.custList, field);
            DialogResult result = productselect.ShowDialog();
            if (result == DialogResult.Yes)
            {
                comboBox4.SelectedValue = productselect.pname;
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            bgSourceqianshu.DataSource = basicSql.getorderDetailIII("%" + textBox3.Text + "%");
            dGridViewqianshu.DataSource = bgSourceqianshu;
            DcolumnSet.colSet(moduleInfo.V_piaoranpaiqi, dGridViewqianshu);
        }
    }
}
